/**
 * 
 */
package com.gwcloud.leetcode.tags.dp;

/**
 * @ClassName   : Leetcode0714 
 * @author      : ganwei 
 * @date        : 2020年5月17日
 * @Description : Leetcode0714 买卖股票的最佳时机含手续费
 */
public class Leetcode0714 {
    public int maxProfit(int[] prices, int fee) {
    	int n = prices.length;
    	int d_i_0 = 0, d_i_1 = Integer.MIN_VALUE;
    	for(int i = 0; i < n; i++){
    		int temp = d_i_0;
    		d_i_0 = Math.max(d_i_0, d_i_1 + prices[i]);
    		d_i_1 = Math.max(d_i_1, temp - prices[i] - fee);
    	}
    	return d_i_0;
    }
}
